/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cubelabs.nexus.dao;

import cubelabs.nexus.entity.OrganizationRequest;
import cubelabs.nexus.entity.User;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 *
 * @author chaitanya
 */
@Repository("OrganizationRequestDao")
public class OrganizationRequestDao extends BaseDAO<OrganizationRequest, Serializable>{

    public List<OrganizationRequest> getPendingRequests(Long userId) {
        String queryStr = "SELECT  orgr.* FROM  OrganizationRequest orgr "
                + "WHERE orgr.user_id=" + userId + " and requestedByUser = false and orgr.accepted = false and orgr.expired = false";
        SQLQuery query = (SQLQuery) getSession().createSQLQuery(queryStr);
        query.addEntity(getPersistentClass());
        return query.list();
    }

    public List<OrganizationRequest> getRequestsFromExperts(Long organizationId) {
         String queryStr = "SELECT  orgr.* FROM  OrganizationRequest orgr "
                + "WHERE orgr.organization_id=" + organizationId + " and requestedByUser = true  and orgr.accepted = false and orgr.expired = false";
        SQLQuery query = (SQLQuery) getSession().createSQLQuery(queryStr);
        query.addEntity(getPersistentClass());
        return query.list();
    }

    public List<User> getExperts(long orgId) {
         String queryStr = "SELECT  u.* FROM  OrganizationRequest orgr ,User u"
                + "WHERE orgr.organization_id=" + orgId + " and  orgr.accepted = true and orgr.user_id=u.id";
        SQLQuery query = (SQLQuery) getSession().createSQLQuery(queryStr);
        query.addEntity(User.class);
        return query.list();
    }
    
}
